import { ipcMain } from 'electron' // 导入 dialog 模块
import { TerminalApi } from '../api/terminal.api'
import { IpcTerminalKeys } from '../../../common/enums/ipc.terminal.enum'
// ipcMain.handle // 监听主进程发送的 IPC 消息
// global.mainWindow?.webContents.send // 发送 IPC 消息给渲染进程(页面)
export function registerTerminalIpc() {
  ipcMain.handle(IpcTerminalKeys.TERMINAL_START, (_) => {
    return TerminalApi.start()
  })
  ipcMain.handle(IpcTerminalKeys.TERMINAL_SEND, (_, command: string) => {
    return TerminalApi.send(_, command)
  })
  ipcMain.handle(IpcTerminalKeys.TERMINAL_KILL, (_) => {
    return TerminalApi.kill()
  })
  ipcMain.handle(IpcTerminalKeys.TERMINAL_CLEAR, (_) => {
    return TerminalApi.clear()
  })
}
